<?php
class Login extends Contorller{

	public function indexAction(){
		$this->layout=null;
		//Fw::app()->getRequestUri();
		$this->render('index');
	}

	/**
	 *
	 */
	public function signinAction(){
		$this->layout=null;

		if(!empty($this->request["username"])&&!empty($this->request["password"])){
			$user = $this->request["username"];
			$pass = md5($this->request["password"]);
			$userInfo = $this->db()->findOne('user',"where:user_name='{$user}'");
            var_dump($userInfo);
			if($userInfo["user_password"] == $pass){
				Fw::app()->setSession("userInfo", $userInfo);
				$this->redirect('site','index');
			}else{
				$this->render('index');
			}
		}else $this->render('index');
	}

	public function registerAction(){
		var_dump($this->request);
		if(empty($this->request["username"])){
			$this->render("register");
		}else{
			$value['user_name']= $this->request["username"];

			$value["user_password"] = md5($this->request["passowrd"]);

			$value["user_email"] = $this->request["userEmail"];

			$value["create_time"] = date("Y-m-d h:i:s");

			$install = $this->db()->insert('user',$value);

			if($install){

				$this->redirect("login", 'index');

			}else{

				$this->render("register");
				
			}
		}
	}

	public function logoutAction(){

		Fw::app()->delSession('userInfo');

		$this->redirect("login", 'index');
	}

	public function changepwdAction(){

		$this->render('changepwd');
	}
	
	
	
}